package hlhj.fhp.checkpoint.atys

import android.support.design.widget.TabLayout
import android.support.v4.app.Fragment
import android.view.View
import hlhj.fhp.checkpoint.BaseAty
import hlhj.fhp.checkpoint.R
import hlhj.fhp.checkpoint.adp.OrderPagerAdp
import hlhj.fhp.checkpoint.fgms.OrderListFgm
import hlhj.fhp.checkpoint.iview.AllViolationView
import hlhj.fhp.checkpoint.javaBean.AllBuyEvent
import hlhj.fhp.checkpoint.presenter.AllViolationPresenter
import kotlinx.android.synthetic.main.aty_allviolation.*
import kotlinx.android.synthetic.main.lo_pub_head.*
import org.greenrobot.eventbus.EventBus

/**
 * Created by Never Fear   on 2018\11\12 0012.
Never More....
违章订单：0：待报价，1：无法代办，2：已报价/代付款，3：处理中，4：已完成
年检订单：0：待报价，1：已报价/代付款，2：处理中，3：已完成
 */
class OrderAty :BaseAty<AllViolationView,AllViolationPresenter>(), AllViolationView {

    private var pagerAdp:OrderPagerAdp?=null
    private var carType=0//1违章 2年检
    private var tag=-1;
    private val fgmLists=ArrayList<Fragment>()
    companion object {
        var type=0
    }

    override fun initView() {
        type=intent?.getIntExtra("type",0)!!
        tvTittle.setText("全部订单")
        pagerAdp=OrderPagerAdp(supportFragmentManager,fgmLists)
        viewPager.adapter=pagerAdp

        viewPager.offscreenPageLimit=10
        tablayout.setupWithViewPager(viewPager)
        tablayout.tabMode=TabLayout.MODE_SCROLLABLE

        carType=intent.getIntExtra("type",0)
        tag=intent.getIntExtra("tag",-1)
        if (carType==1){
            btRightText.text="全部支付"
            btRightText.visibility= View.VISIBLE
        }
    }

    override fun logicStart() {
        when (type){
            1->{//违章
                fgmLists.add(OrderListFgm.getInstance("全部",-1,2))
                fgmLists.add(OrderListFgm.getInstance("未报价",0,2))
                fgmLists.add(OrderListFgm.getInstance("无法代办",1,2))
                fgmLists.add(OrderListFgm.getInstance("未付款",2,2))
                fgmLists.add(OrderListFgm.getInstance("处理中",3,2))
                fgmLists.add(OrderListFgm.getInstance("已完成",4,2))
                btAll.visibility=View.VISIBLE
                btAllTv.visibility=View.VISIBLE
            }
            2->{
                fgmLists.add(OrderListFgm.getInstance("全部",-1,1))
                fgmLists.add(OrderListFgm.getInstance("待支付",0,1))
                fgmLists.add(OrderListFgm.getInstance("已撤销",1,1))
                fgmLists.add(OrderListFgm.getInstance("处理中",2,1))
                fgmLists.add(OrderListFgm.getInstance("已完成",3,1))

                btAll.visibility=View.GONE
                btAllTv.visibility=View.GONE
            }
        }



        pagerAdp?.notifyDataSetChanged()

        when(tag){
            -1->{

            }
            1->{
                if (type==1){
                    viewPager.currentItem=3
                }else{
                    viewPager.currentItem=1
                }

            }
            2->{
                if (type==1){
                    viewPager.currentItem=2
                }else{
                    viewPager.currentItem=3
                }
            }
            3->{
                if (type==1){
                    viewPager.currentItem=4
                }else{
                    viewPager.currentItem=2
                }
            }
            4->{
                if (type==1){
                    viewPager.currentItem=5
                }else{
                    viewPager.currentItem=4
                }
            }
        }



    }

    override fun setListener() {
        btAll.setOnClickListener {
            EventBus.getDefault().post(AllBuyEvent())

        }
        btRightText.setOnClickListener {
            EventBus.getDefault().post(AllBuyEvent())
        }
    }

    override fun bindView(): AllViolationView {
        return this
    }

    override fun createPresenter(): AllViolationPresenter {
        return AllViolationPresenter()
    }

    override val contentId: Int
        get() = R.layout.aty_allviolation
}